package com.hp.attendance.service;

import com.hp.attendance.dao.OvertimeDao;
import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.Overtime;
import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.entity.dto.DepOvertimeDto;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class OvertimeService {
    private OvertimeDao overtimeDao=new OvertimeDao();
    private DepOvertimeDto depOvertimeDto=new DepOvertimeDto();
    /**
     * 分页查询菜单列表
     * @param pageNo 当前页
     * @param pageSize 每页显示的条数
     * @return
     */
    public PageInfo<DepOvertimeDto> getPage(int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<DepOvertimeDto> page = new PageInfo<DepOvertimeDto>();
        //查询分页的数据                           2       10
        List<DepOvertimeDto> list = overtimeDao.getLimitList(pageNo, pageSize);
        page.setRecords(list);
        //查询总记录条数
        long total = overtimeDao.getTotal();
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;

    }

    /**
     * 查询所有加班数据
     * @return
     * @throws SQLException
     */
    public List<Overtime> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        List<Overtime> list = overtimeDao.getList();
        return list;
    }
    /**
     * 查询所有部门的列表
     * @return
     * @throws SQLException
     */
    public List<Department> getDepList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        List<Department> list = overtimeDao.getDepList();
        return list;
    }
    /**
     * 查询所有员工的列表
     * @return
     * @throws SQLException
     */
    public List<Employee> getEmpList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        List<Employee> list = overtimeDao.getEmpList();
        return list;
    }
    /**
     * 删除角色
     * @param id
     */
    public void delOvertime(int id) throws SQLException, IOException, ClassNotFoundException {
       overtimeDao.delOvertime(id);
    }
    /**
     * 添加加班
     * @param overtime
     * @throws SQLException
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public void addOvertime(Overtime overtime) throws SQLException, IOException, ClassNotFoundException {
        overtimeDao.addOvertime(overtime);
    }

    /**
     *通过部门名称查找对应加班列表
     */
    public Overtime getOvertimeByDep(String depname) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        Overtime overtime = overtimeDao.getOvertimeByDep(depname);
        return overtime;
    }
    /**
     *通过员工名称查找对应加班列表
     */
    public Overtime getOvertimeByEmp(String empname) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        Overtime overtime = overtimeDao.getOvertimeByEmp(empname);
        return  overtime;
    }
    /**
     * 修改加班
     * @param overtime
     */
    public void updateOvertime(Overtime overtime) throws SQLException, IOException, ClassNotFoundException {
      overtimeDao.updateOvertime(overtime);
    }
    /**
     * 根据department_number查询id
     * @param
     * @return
     */
    public Overtime getOvertime(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        Overtime overtime = overtimeDao.getOvertime(id);
        return overtime;
    }

    /**
     * 查询员工的列表通过部门号
     * @return
     * @throws SQLException
     */
    public List<Employee> getEmpListByDep(int dep_num) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        List<Employee> list = overtimeDao.getEmpListByDep(dep_num);
        return list;
    }

}
